package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.ImmunizationSubRecordDao;
import com.jiantong.work.model.ImmunizationSubRecord;
import com.jiantong.work.service.ImmunizationSubRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * Created by mz on 26/7/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class ImmunizationSubRecordWriteServiceImpl implements ImmunizationSubRecordWriteService{

    private final ImmunizationSubRecordDao immunizationSubRecordDao;

    public ImmunizationSubRecordWriteServiceImpl(ImmunizationSubRecordDao immunizationSubRecordDao) {
        this.immunizationSubRecordDao = immunizationSubRecordDao;
    }

    /**
     * 添加一次免疫
     *
     * @param immunizationSubRecord 免疫信息的对象
     * @return Response<Long>
     */
    @Override
    public Response<Long> create(ImmunizationSubRecord immunizationSubRecord) {
        try{
            immunizationSubRecordDao.create(immunizationSubRecord);
            return Response.ok(immunizationSubRecord.getId());
        }catch (Exception e){
            log.error("failed to create case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to create");
        }
    }

    /**
     * 更新一次免疫
     *
     * @param immunizationSubRecord 免疫信息的对象
     * @return Response<Boolean>
     */
    @Override
    public Response<Boolean> update(ImmunizationSubRecord immunizationSubRecord) {
        try{
            return Response.ok(immunizationSubRecordDao.update(immunizationSubRecord));
        }catch (Exception e){
            log.error("failed to update case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to update");
        }
    }
}
